package com.hang.config;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;

import javax.annotation.Resource;

@Configuration
public class MongoConverterConfig implements InitializingBean {

    @Resource
    private MappingMongoConverter mappingConverter;

    @Override
    public void afterPropertiesSet() throws Exception {
        //去除插入数据库的_class字段
        mappingConverter.setTypeMapper(new DefaultMongoTypeMapper(null));
    }
}